package com.amigo.online.provider.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.param.dto.user.InvoiceAddressDto;
import com.amigo.online.provider.user.common.GlobalController;
import com.amigo.online.provider.user.service.InvoiceService;

@RestController
@RequestMapping(value = "/invoice")
public class InvoiceController extends BaseController {


    @Autowired
    private InvoiceService invoiceService;

    @PostMapping("/create")
    public ResponseEntity<Response> createAddress(@RequestBody InvoiceAddressDto addressDto) {
        Long userId = GlobalController.getNowUser().getId();
        addressDto.setUserId(userId);
        return success(invoiceService.createInvoiceAddress(addressDto));
    }

    @GetMapping("/my")
    public ResponseEntity<Response> getMyAddress() {
        Long userId = GlobalController.getNowUser().getId();
        return success(invoiceService.selectAddressByUser(userId));
    }

    @PostMapping("/update")
    public ResponseEntity<Response> updateAddress(@RequestBody InvoiceAddressDto addressDto) {
        addressDto.setUserId(GlobalController.getNowUser().getId());
        return success(invoiceService.updateInvoiceAddress(addressDto));
    }

}
